home *** CD-ROM | disk | FTP | other *** search
- /*
- File: TranslationComponent.c
-
- Contains: Source code of a component shell for a translation extension
-
- Copyright: © 1994,1998 by Apple Computer, Inc., all rights reserved.
- */
-
- // ------------------------------------------------------------------------------------
- //
- // This file only implements the skeleton of a component, which can be used as the
- // shell of a translation extension.
- //
- // Since we will implement a FAT component, This code will be used to generate
- // two code resources, one for 68K, one for PowerPC.
- //
- // One noticeable difference between the 68K code and PowerPC code is that any-
- // time your code uses a callback function(ProcPtr), you must use a UniversalProcPtr
- // in the PowerPC code instead. So when your native component dispatches to internal
- // functions using CallComponentFunction or CallComponentFunctionWithStorage you must
- // use a UniversalProcPtr.
- //
- // There are two methods to build a UniversalProcPtr, one is using NewRoutine-
- // Descriptor, another is declaring a global RoutineDescriptor for this code fragment.
- // The disadvantage for the first method is that you must call DisposeRoutineDescriptor
- // to dispose of routine descriptors you have created.
-
- #include <Types.h>
- #include <Files.h>
- #include <MixedMode.h>
- #include <Traps.h>
- #include <Errors.h>
- #include <Memory.h>
- #include <Resources.h>
- #include <Components.h>
- #include <TranslationExtensions.h>
-
- #include "TranslationComponent.h"
-
- // ------------------------------------------------------------------------------------------
- // Global routine descriptor for call back function.
-
- #ifdef powerc
- INSTANTIATE_ROUTINE_DESCRIPTOR(DoGetFileTranslationList);
- INSTANTIATE_ROUTINE_DESCRIPTOR(DoIdentifyFile);
- INSTANTIATE_ROUTINE_DESCRIPTOR(DoTranslateFile);
- INSTANTIATE_ROUTINE_DESCRIPTOR(DoGetScrapTranslationList);
- INSTANTIATE_ROUTINE_DESCRIPTOR(DoIdentifyScrap);
- INSTANTIATE_ROUTINE_DESCRIPTOR(DoTranslateScrap);
- INSTANTIATE_ROUTINE_DESCRIPTOR(DoGetTranslatedFilename);
- #endif
-
-
- // ------------------------------------------------------------------------------------------
- //
- // This is the actual entry point for the translation extension. It handles some Component
- // Manager setup, but its main task is to dispatch to the extension subroutines when known
- // selectors are encountered.
- //
- //
- pascal ComponentResult main( ComponentParameters *params, Handle storage )
- {
-
- ComponentResult result;
-
- switch (params->what)
- {
-
- case kComponentOpenSelect: // Allocate memory for storage when component is opened
- { ComponentInstance self = (ComponentInstance)params->params[0];
- Handle h = NewHandle(sizeof(ComponentInstance)); // allocate storage
-
- if ( h != NULL )
- {
- (**(ComponentInstance**)h) = self; // put instance in storage
- SetComponentInstanceStorage(self, h);
- result = noErr;
- }
- else
- result = MemError();
- }
- break;
-
- case kComponentCloseSelect: // Clean up memory when component is closed
- if( storage != nil )
- DisposeHandle(storage);
- result = noErr;
- break;
-
- case kComponentCanDoSelect: // Component Manager needs to know what selectors we can handle
- {
- short selector = *(short*)params->params;
-
- if ( (( kComponentVersionSelect <= selector) && (selector <= kComponentOpenSelect))
- || ((kTranslateGetFileTranslationList <= selector) && (selector <= kTranslateTranslateFile))
- || ((kTranslateGetScrapTranslationList <= selector) && (selector <= kTranslateTranslateScrap)) )
- result = 1;
- else
- result = 0;
- };
- break;
- case kComponentVersionSelect: // Which version of this component
- result = 0;
- break;
-
- case kTranslateGetFileTranslationList: // Want file translation list
- result = CallComponentFunctionWithStorageUniv((Handle)**(ComponentInstance**)storage, params
- , DoGetFileTranslationList);
- break;
-
- case kTranslateIdentifyFile: // Want to identify file?
- result = CallComponentFunctionWithStorageUniv((Handle)**(ComponentInstance**)storage, params
- , DoIdentifyFile);
- break;
-
- case kTranslateTranslateFile: // Want to translate file?
- result = CallComponentFunctionWithStorageUniv((Handle)**(ComponentInstance**)storage, params
- , DoTranslateFile);
- break;
-
- case kTranslateGetScrapTranslationList: // Want scrap translation list?
- result = CallComponentFunctionWithStorageUniv((Handle)**(ComponentInstance**)storage, params
- , DoGetScrapTranslationList);
- break;
-
- case kTranslateIdentifyScrap: // Want to identify scrap?
- result = CallComponentFunctionWithStorageUniv((Handle)**(ComponentInstance**)storage, params
- , DoIdentifyScrap);
- break;
-
- case kTranslateTranslateScrap: // Want to translate scrap?
- result = CallComponentFunctionWithStorageUniv((Handle)**(ComponentInstance**)storage, params
- , DoTranslateScrap);
- break;
-
- default:
- result = badComponentSelector;
-
- };
-
- return result;
- }
-
-
-